/*
 * Copyright [2022] [https://www.xiaonuo.vip]
 *
 * Snowy采用APACHE LICENSE 2.0开源协议，您在使用过程中，需要注意以下几点：
 *
 * 1.请不要删除和修改根目录下的LICENSE文件。
 * 2.请不要删除和修改Snowy源码头部的版权声明。
 * 3.本项目代码可免费商业使用，商业使用请保留源码和相关描述文件的项目出处，作者声明等。
 * 4.分发源码时候，请注明软件出处 https://www.xiaonuo.vip
 * 5.不可二次分发开源参与同类竞品，如有想法可联系团队xiaonuobase@qq.com商议合作。
 * 6.若您的项目无法满足以上几点，需要更多功能代码，获取Snowy商业授权许可，请在官网购买授权，地址为 https://www.xiaonuo.vip
 */
package vip.xiaonuo.client.modular.cabinet;

import cn.hutool.core.bean.BeanUtil;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.auth.core.util.StpClientUtil;
import vip.xiaonuo.biz.modular.cabinetdoor.entity.BizCabinetDoor;
import vip.xiaonuo.biz.modular.cabinetdoor.service.BizCabinetDoorService;
import vip.xiaonuo.biz.modular.cabinetdoor.vo.ClientCabinetDoorForAdmin;
import vip.xiaonuo.biz.modular.cabinetdoor.vo.ClientCabinetTree;
import vip.xiaonuo.biz.modular.cabinetgroup.entity.BizCabinetGroup;
import vip.xiaonuo.biz.modular.cabinetgroup.service.BizCabinetGroupService;
import vip.xiaonuo.biz.modular.cabinetgroup.vo.ClientCabinetGroup;
import vip.xiaonuo.biz.modular.cabinetinfo.entity.BizCabinetInfo;
import vip.xiaonuo.biz.modular.cabinetinfo.service.BizCabinetInfoService;
import vip.xiaonuo.biz.modular.cabinetpermission.param.BizCabinetPermissionListParam;
import vip.xiaonuo.biz.modular.cabinetpermission.service.BizCabinetPermissionService;
import vip.xiaonuo.biz.modular.cabinetpermission.vo.BizCabinetDoorPermissionResp;
import vip.xiaonuo.common.pojo.CommonResult;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 管理模式-我的柜子
 *
 * @author kongxm
 * @date 2022/11/13 16:14
 */
@Api(tags = "管理模式-我的柜子")
@ApiSupport(author = "kongxm")
@RestController
@Validated
public class ClientAdminCabinetController {
    @Resource
    private BizCabinetGroupService bizCabinetGroupService;
    @Resource
    private BizCabinetInfoService bizCabinetInfoService;
    @Resource
    private BizCabinetDoorService bizCabinetDoorService;
    @Resource
    private BizCabinetPermissionService bizCabinetPermissionService;

    /**
     * 获取组柜柜子柜门信息
     *
     * @author kongxm
     * @date 2022/11/13 16:14
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation("组柜柜子柜门树结构")
    @GetMapping("/client/admincabinet/tree")
    public CommonResult<List<ClientCabinetTree>> getCabinetTree(String searchKey, Integer goodsType) {
        return CommonResult.data(bizCabinetDoorService.getCabinetTree(searchKey, goodsType));
    }

    /**
     * 查看柜门授权用户
     *
     * @author kongxm
     * @date 2022/11/13 16:14
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation("查看柜门授权用户")
    @GetMapping("/client/admincabinet/perm/list")
    public CommonResult<BizCabinetDoorPermissionResp> getPermList(BizCabinetPermissionListParam param) {
        return CommonResult.data(bizCabinetPermissionService.listPermission(param));
    }

    /**
     * 根据客户端登录用户权限，获取组柜不分页
     *
     * @author kongxm
     * @date 2022/11/12 22:13
     */
    @ApiOperationSupport(order = 7)
    @ApiOperation("根据客户端登录用户权限，获取组柜不分页")
    @GetMapping("/client/admincabinet/cabinetgroup/list")
    public CommonResult<List<ClientCabinetGroup>> listClientCabinetGroup(Integer cabinetGroupType) {
        List<ClientCabinetGroup> dataList = bizCabinetGroupService.listCabinetGroupByAdminId(
                StpClientUtil.getLoginIdAsString() ,cabinetGroupType).stream().map(item->{
            ClientCabinetGroup cabinetGroup = new ClientCabinetGroup();
            BeanUtil.copyProperties(item,cabinetGroup);
            return cabinetGroup;
        }).collect(Collectors.toList());
        return CommonResult.data(dataList);
    }

    /**
     * 根据客户端登录用户权限，获取柜子不分页
     *
     * @author kongxm
     * @date 2022/11/12 22:13
     */
    @ApiOperationSupport(order = 7)
    @ApiOperation("根据客户端登录用户权限，获取柜子不分页")
    @GetMapping("/client/admincabinet/cabinetinfo/list")
    public CommonResult<List<BizCabinetInfo>> listClientCabinetInfo(Integer cabinetInfoType, String cabinetGroupId) {
        return CommonResult.data(bizCabinetInfoService.listCabinetInfoByAdminId(
                StpClientUtil.getLoginIdAsString(),
                null, cabinetInfoType, cabinetGroupId));
    }

    /**
     * 根据客户端登录用户权限，获取柜子不分页
     *
     * @author kongxm
     * @date 2022/11/12 22:13
     */
    @ApiOperationSupport(order = 7)
    @ApiOperation("根据客户端登录用户权限，获取柜门不分页")
    @GetMapping("/client/admincabinet/cabinetdoor/list")
    public CommonResult<List<ClientCabinetDoorForAdmin>> listClientCabinetDoor(Integer cabinetDoorType, String cabinetInfoId) {
        return CommonResult.data(bizCabinetDoorService.listCabinetDoorByAdminId(
                StpClientUtil.getLoginIdAsString(),
                 cabinetDoorType, cabinetInfoId));
    }
}
